package com.weiyin.examination.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StyleRes;
import android.view.View;
import android.widget.ImageView;

import com.weiyin.examination.R;
import com.weiyin.examination.application.Constant;
import com.weiyin.examination.listener.DialogResultInterface;
import com.weiyin.examination.util.LayoutHelper;

/**
 * @author njf
 * @date 2017/11/23
 */

public class BottomDialog extends Dialog implements View.OnClickListener {
    private Activity activity;
    private ImageView bottomDialogTreble, bottomDialogBass;
    private DialogResultInterface dialogResultInterface;

    public void setDialogResultInterface(DialogResultInterface dialogResultInterface) {
        this.dialogResultInterface = dialogResultInterface;
    }

    public BottomDialog(@NonNull Activity context) {
        super(context);
        this.activity = context;
    }

    public BottomDialog(@NonNull Activity context, @StyleRes int themeResId) {
        super(context, themeResId);
        this.activity = context;
    }

    protected BottomDialog(@NonNull Activity context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        this.activity = context;
    }

    @Override
    public void dismiss() {
        if (dialogResultInterface != null) {
            dialogResultInterface.result(Constant.BOTTOM_RESULT, Constant.BOTTOM_DISMISS, "0");
        }
        super.dismiss();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.bottom_dialog_layout);
        LayoutHelper layoutHelper = new LayoutHelper(activity);
        layoutHelper.scaleView(findViewById(R.id.bottomDialogLayout));

        initView();
    }

    private void initView() {
        bottomDialogTreble = (ImageView) findViewById(R.id.bottomDialogTreble);
        bottomDialogBass = (ImageView) findViewById(R.id.bottomDialogBass);

        bottomDialogTreble.setOnClickListener(this);
        bottomDialogBass.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.bottomDialogTreble:
                if (dialogResultInterface != null) {
                    dialogResultInterface.result(Constant.BOTTOM_RESULT, Constant.BOTTOM_START, "0");
                }
                break;
            case R.id.bottomDialogBass:
                if (dialogResultInterface != null) {
                    dialogResultInterface.result(Constant.BOTTOM_RESULT, Constant.BOTTOM_END, "0");
                }
                break;
            default:
                break;
        }
    }
}
